#include "../include/scNet/Server.hpp"
#include <iostream>

int main()
{
	scNet::Server server;

	// 设置 接收请求的处理器
	server.setRequestHandler([] (const std::string& request) {
		// 将收到的来自客户端的请求打印在控制台
		std::cout << "Client received: " << request << std::endl;
		return "HTTP/1.1 200 OK\r\n"
               "Content-Type: text/plain\r\n"
               "\r\n"
               "Hello from scNet Server!";
	});

	// 打开服务器
	try {
		server.start(8080);
		// 给出运行提示 
		std::cout << "Server is active on 8080..." << std::endl;

		// 循环给 sleepfor 防止cpu占用过高 导致错误然后关闭服务器 
		while (true) 
			std::this_thread::sleep_for(std::chrono::seconds(1));
	} catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
	return 0;
}
